<template>
  <div class="inOutSaveDaily">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">发运情况分析</span>
      </div>
      <s-table
        :table="table"
        @http="tableWatch">
        <el-form-item label="选择时间" prop="cjsj">
          <el-date-picker
            v-model="autoVue_table_cjsj"
            type="daterange"
            placeholder="选择日期范围">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="产品名称" prop="goodsMc">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_goodsMc"
                    placeholder="产品名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="产品编码" prop="goodsBh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_goodsBh"
                    placeholder="产品编码" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item slot="multiSelect" label="多选操作" prop="multiSelect" v-if="table.multiSelect">
          <el-row>
            <el-col :span="8">
              <el-button size="small" type="info" @click="tableExport('')">多选导出</el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </s-table>
    </el-card>
  </div>
</template>

<script>
  import {AutoVue} from '~/plugins/Tools';
  export default AutoVue({
    name: 'journaling_inOutSaveDaily-FEcarWms',
    head: {
      'title': '发运情况分析',
      'meta': [
        { 'hid': 'description', 'name': 'description', 'content': '乐速科技平台 进出存合并 查看进出存合并信息' },
      ],
    },
    store: ['USER'],
    data: {
      table: {
        column: [
          { label: '产品编码',
            prop: 'goodsBh',
            minWidth: '0px',
            cRemarks: '',
            search: true},
          { label: '产品名称',
            prop: 'goodsMc',
            minWidth: '0px',
            cRemarks: '',
            search: true },
          { label: '销售数量',
            prop: 'xssl',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '已发货数量',
            prop: 'fysl',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '欠货数量',
            prop: 'qhsl',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '抵扣数量',
            prop: 'dksl',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '单价',
            prop: 'je',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '销售额',
            prop: 'xse',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '运费',
            prop: 'yf',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '运费/销售额',
            prop: 'zb',
            minWidth: '0px',
            cRemarks: '',
            search: false },
          { label: '选择时间',
            prop: 'cjsj',
            minWidth: '0px',
            cRemarks: '',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 6);
            },
            type: 'DateRange',
            search: true },
        ],
        url: '/statistics/shipmentStatistics',
        option: {
          cjsj_start: '',
          cjsj_end: '',
          page: 1,
          rows: 10,
        },
        key: 'id',
        tableColumn: 10,
      },
    },
    methods: {
      tableExport (row) {
        let tableRef = 'table';

        let hpids = [];
        if (row) {
          hpids.push(row.goodsId);
        } else {
          this[tableRef].multipleSelection.forEach(item => {
            hpids.push(item.goodsId);
          });
        }
        this.$confirm('您将导出货品发运情况分析报表数据。', '确认导出？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              let option = Object.assign({}, this['autoVue_' + tableRef]);
              await this.p({
                url: '/statistics/shipmentStatisticsExport',
                method: 'post',
                responseType: 'blob',
                data: {
                  hpids,
                  ...option,
                },
              });
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
    },
    transition: 'slide-fade',
    mounted: function () {
      this.tableWatch('table');
    },
  });
</script>
<style scoped lang="scss">
  .box-card {
    margin: 20px;
  }

  .createTimeSpan {
    display: block;
    margin-top: 34px;
  }

  @media screen and (max-width: 800px) {
    .createTimeSpan {
      margin-top: 0;
    }
    .box-card {
      margin: 0;
    }
  }

  .el-select {
    width: 100%;
  }
</style>

<style lang="scss">

</style>
